<template>
  <div id="app">
    <!-- 根据路由判断显示前台还是后台布局 -->
    <template v-if="isAdminRoute">
      <!-- 管理后台布局 -->
      <admin-layout>
        <router-view/>
      </admin-layout>
    </template>
    <template v-else>
      <!-- 前台布局 -->
      <Navbar />
      
      <!-- 主要内容区域 -->
      <main>
        <router-view/>
      </main>
    </template>
    <AiChatBox />
  </div>
</template>

<script>
import Navbar from '@/components/Navbar.vue'
import AdminLayout from '@/admin/components/AdminLayout.vue'
import AiChatBox from '@/components/AiChatBox.vue'

export default {
  name: 'App',
  components: {
    Navbar,
    AdminLayout,
    AiChatBox
  },
  computed: {
    isAdminRoute() {
      // 判断当前路由是否是管理后台路由
      return this.$route.path.startsWith('/admin')
    }
  },
  created() {
    // 当在管理后台路由时
    if (this.isAdminRoute && this.$route.path !== '/admin/login') {
      // 检查是否已登录
      const adminToken = localStorage.getItem('adminToken');
      if (!adminToken) {
        // 未登录则重定向到登录页
        this.$router.push('/admin/login');
      }
    }
  }
}
</script>

<style>
/* 重置浏览器默认样式 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: #f5f5f5;
  color: #333;
  line-height: 1.6;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
}

/* 确保main内容不被导航栏遮挡 */
main {
  margin-top: 70px;
  flex: 1;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 挑战页面样式 */
.challenge-detail-page {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  margin: 20px auto;
  padding: 30px;
  max-width: 1000px;
}

/* 绿色样式 */
.btn-primary {
  background-color: #4CAF50;
  color: white;
  border: none;
}

.btn-primary:hover {
  background-color: #3d8b40;
}

.btn-outline {
  background-color: transparent;
  color: #4CAF50;
  border: 1px solid #4CAF50;
}

.btn-outline:hover {
  background-color: rgba(76, 175, 80, 0.1);
}

/* 通用响应式调整 */
@media (max-width: 768px) {
  .container {
    padding: 0 15px;
  }
  
  .challenge-detail-page {
    padding: 20px;
    margin: 15px auto;
  }
}

/* 管理后台按钮样式 */
.admin-btn {
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 500;
  border: none;
  background-color: #f0f0f0;
}

.admin-btn-primary {
  background-color: #1890ff;
  color: white;
}

.admin-btn-primary:hover {
  background-color: #40a9ff;
}

.admin-btn-danger {
  background-color: #ff4d4f;
  color: white;
}

.admin-btn-danger:hover {
  background-color: #ff7875;
}

.admin-btn-success {
  background-color: #52c41a;
  color: white;
}

.admin-btn-success:hover {
  background-color: #73d13d;
}

/* 管理后台表单样式 */
.admin-form-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  transition: all 0.3s;
}

.admin-form-input:focus {
  border-color: #40a9ff;
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
  outline: none;
}

.admin-form-error {
  color: #ff4d4f;
  margin-top: 4px;
  font-size: 14px;
}
</style>

